
import org.authsum.stitches.Helper


class ContentDefControllerTests extends GroovyTestCase {

	def helper

    def stitchesService

	void testIndex() {

    	def controller = new ContentDefController()
    	controller.stitchesService  = stitchesService
    	//vc.request.parameters = [contentversionid:mycontentid,viewsecuretoken:imageContentVersion.content.viewSecureToken,attributename:binaryAttributeName]
    	def myindex = controller.index()
    	def contentDefResponse = myindex['contentDefResponse']
    	//what does this test?
    	//assertFalse contentDefResponse.contentDefHolders.contentDefHolder.isEmpty()
    	//println myindex

    }

    
    void testSaveContentDef()  {

    		def controller = new ContentDefController()
        	controller.stitchesService  = stitchesService
        	controller.request.parameters = ['name':"testSaveContentDef",'description':"testSaveContentDef",'mimeType':"application/whatever",'baseType':"Other"]
    		controller.saveContentDef()
    			
    		
    }
    
    
    void testAddAttribute() {
    	

		def controller = new ContentDefController()
    	controller.stitchesService  = stitchesService
		Long contentDefId = helper.getContentDefId(name:"testAddAttribute")
		controller.request.parameters = ['contentDefId':contentDefId.toString(),'name':"new-attribute",'description':"added attribute",'valueType':"Integer",'required':"true"]
    		
		controller.addAttribute()
    	
    
    }

    
    void testRemoveAttribute() {
    	

		def controller = new ContentDefController()
    	controller.stitchesService  = stitchesService
		Long contentDefId = helper.getContentDefId(name:"testRemoveAttribute")
		Long attributeId = helper.getAttributeId(attributeName:'testRemoveAttribute',contentDefId:contentDefId,valueType:"Integer")
		controller.request.parameters = ['contentDefId':contentDefId.toString(),'attributeId':attributeId.toString()]
    		
		println "attributeId=" + attributeId.toString()
		//need to pass contentDefId and attributeHolder.id
		//request.attributeHolder.id
		controller.removeAttribute()
    	
    
    }
    
    
}
